package web.base.system.util;

import blue.core.common.Page;
import blue.core.util.BeanUtil;
import web.base.system.message.RoleRequest;
import web.base.system.message.RoleResponse;
import web.base.system.model.Role;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-02
 */
public class RoleConvertor
{
	private RoleConvertor()
	{
	}

	public static Role toRole(RoleRequest request)
	{
		return BeanUtil.createBean(Role.class, request);
	}

	public static RoleResponse toResponse(Role role)
	{
		return BeanUtil.createBean(RoleResponse.class, role);
	}

	public static List<RoleResponse> toResponse(List<Role> list)
	{
		List<RoleResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;

		for (Role role : list)
		{
			responseList.add(toResponse(role));
		}
		return responseList;
	}

	public static Page toResponse(Page page)
	{
		Page responsePage = new Page(page.getItemsPerPage(), page.getPageNumber());
		responsePage.setTotalResult(page.getTotalResult());
		responsePage.setResults(toResponse(page.getResults()));
		return responsePage;
	}

}
